home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Utilities
/
Programming
/
Gooey 1.2
/
Gooey 68K ƒ
/
C++ Templates
/
mmWindow.c
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
Text File
|
1994-06-08
|
37.3 KB
|
1,081 lines
|
[
TEXT/KAHL
]
$$Loop Windows
$$Message MM Window, mm:mmW_$Worksheet.name$.cp
$$File mm:mmW_$Worksheet.name$.cp
/* mmW_$Worksheet.name$ Handle this Window */
/* $CopyRight$ */
/*
File name: mmW_$Worksheet.name$
Function: Handle a Window
History: $Date$ Original by $Author$
*/
#include "mmCommon$Prototype.name$.h" /* Common */
#include "Common$Prototype.name$.h" /* Common */
/* ======================================================= */
$$if Worksheet.Scrollbars
/* ======================================================= */
/* Routine: HandleScrollBar */
/* Purpose: Handle a ScrollBar being pressed */
void CmmW$Worksheet.name$::HandleScrollBar(short code,ControlHandle theControl,Point myPt)
{
long RefCon; /* RefCon for controls */
RefCon = GetCRefCon(theControl); /* get control refcon */
switch (RefCon) /* Select correct scrollbar */
{
$$Loop Control.type = ScrollBar
case ResC_$Control.name$: /* Scroll bar, $Control.FullName$ */
HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/* code,Inc,PageInc,handle */
break;
$$EndLoop
$$Loop Control.type = UGauge
case ResC_$Control.name$: /* Plugin gauge, $Control.FullName$ */
HandleWScrollBar(myPt,code,$Control.StepScroll$,$Control.PageScroll$,theControl);/* code,Inc,PageInc,handle */
break;
$$EndLoop
$$if Worksheet.Document
$$if Worksheet.ScrollHorz
case 12345L:
HandleWScrollBar(myPt,code,1,10,theControl);
break;
$$endif
$$if Worksheet.ScrollVert
case 12346L:
HandleWScrollBar(myPt,code,1,10,theControl);
break;
$$endif
$$endif Worksheet.Document
default: /* allow other buttons, trap for debug */
break; /* end of otherwise */
} /* end of switch */
}
$$endif
/* ======================================================= */
/* ======================================================= */
void CmmW$Worksheet.name$::InitRecord($Worksheet.name$PRec theWS)
{
theWS->theWindow = nil; /* Make sure other routines know we are not valid yet */
theWS->ExtrasHdl = nil; /* Not used by MM code, dedicated to user code */
$$if Worksheet.Document
$$if Worksheet.ScrollHorz
theWS->ScrollHHandle = nil; /* Scrollbar is not valid yet */
theWS->ScrollHLeftOffset = -1; /* Offset of control from left side */
$$endif
$$if Worksheet.ScrollVert
theWS->ScrollVHandle = nil; /* Scrollbar is not valid yet */
theWS->ScrollVTopOffset = -1; /* Offset of control from top edge */
$$endif
$$endif Worksheet.Document
/* Set the window back color */
theWS->WindowBackColor.red = 0x$Worksheet.RedBackColor$;
theWS->WindowBackColor.green = 0x$Worksheet.GreenBackColor$;
theWS->WindowBackColor.blue = 0x$Worksheet.BlueBackColor$;
$$Loop Control.type = Button
theWS->Enable_$Control.name$ = $Control.Active$; /* Button, $Control.FullName$ */
$$EndLoop
$$Loop Control.type = HotRect
$$if Control.HotSpot
theWS->Enable_$Control.name$ = $Control.Active$; /* HotSpot, $Control.FullName$ */
$$endif
$$EndLoop
$$Loop Control.type = Checkbox
theWS->Enable_$Control.name$ = $Control.Active$; /* Checkbox, $Control.FullName$ */
$$if Control.Selected
theWS->Value_$Control.name$ = 1;
$$endif
$$if Control.Unselected
theWS->Value_$Control.name$ = 0;
$$endif
$$EndLoop
$$Loop Control.type = Radio
theWS->Enable_$Control.name$ = $Control.Active$; /* Radio, $Control.FullName$ */
$$if Control.Selected
theWS->Value_$Control.name$ = 1;
$$endif
$$if Control.Unselected
theWS->Value_$Control.name$ = 0;
$$endif
$$EndLoop
$$Loop Control.type = ScrollBar
theWS->Enable_$Control.name$ = $Control.Active$; /* ScrollBar, $Control.FullName$ */
theWS->Value_$Control.name$ = $Control.ValueScroll$;
$$EndLoop
$$Loop Control.type = Icon
$$if Control.NonGraphic
theWS->Enable_$Control.name$ = $Control.Active$; /* Icon button, $Control.FullName$ */
$$endif
$$EndLoop
$$Loop Control.type = Sicn
$$if Control.NonGraphic
theWS->Enable_$Control.name$ = $Control.Active$; /* Sicn button, $Control.FullName$ */
$$endif
$$EndLoop
$$Loop Control.type = Picture
$$if Control.NonGraphic
theWS->Enable_$Control.name$ = $Control.Active$; /* Picture button, $Control.FullName$ */
$$endif
$$EndLoop
$$Loop Control.type = UButton
theWS->Enable_$Control.name$ = $Control.Active$; /* Plugin button, $Control.FullName$ */
$$EndLoop
$$Loop Control.type = UToggle
theWS->Enable_$Control.name$ = $Control.Active$; /* Plugin toggle, $Control.FullName$ */
$$if Control.Selected
theWS->Value_$Control.name$ = 1;
$$endif
$$if Control.Unselected
theWS->Value_$Control.name$ = 0;
$$endif
$$EndLoop
$$Loop Control.type = UGauge
theWS->Enable_$Control.name$ = $Control.Active$; /* Plugin gauge, $Control.FullName$ */
theWS->Value_$Control.name$ = $Control.ValueScroll$;
$$EndLoop
$$Loop Control.type = Popup
theWS->Enable_$Control.name$ = $Control.Active$; /* Popup menu, $Control.FullName$ */
theWS->Value_$Control.name$ = $Control.SelectedID$;
$$EndLoop
$$Loop Control.type = Palette
theWS->Enable_$Control.name$ = $Control.Active$; /* Palette, $Control.FullName$ */
theWS->Value_$Control.name$ = $Control.ValueScroll$;
$$EndLoop
$$Loop Control.type = List
theWS->List_$Control.name$ = nil; /* List, $Control.FullName$ */
SetRect(&theWS->ListRect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$); /* left,top,right,bottom */
$$EndLoop
$$Loop Control.type = EditText
theWS->TE_$Control.name$ = nil; /* Edit Text, $Control.FullName$ */
SetRect(&theWS->TERect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$); /* left,top,right,bottom */
GetIndString(theWS->TEStr_$Control.name$,sResC_$Control.name$,1);/* ...Edit text, default value */
$$EndLoop
}
/* ======================================================= */
void CmmW$Worksheet.name$::LocateInstance(WindowPtr theWindow)
{
$Worksheet.name$PRec ckWS,theWS;
theWS = nil; /* Init to not found */
ckWS = this->ListRecPtr;
while (ckWS != nil)
{
if (ckWS->theWindow == theWindow)
theWS = ckWS;
ckWS = ckWS->Next;
}
this->RecPtr = theWS;
}
/* ======================================================= */
/* Routine: Init */
/* Purpose: Initialize our window data to not in use yet */
void CmmW$Worksheet.name$::Init()
{
inherited::Init();
$$if Worksheet.SavePosition
theWindowLocRec.Loc_$Worksheet.name$.left = $Worksheet.LeftPosition$; /* Set default Horz position */
theWindowLocRec.Loc_$Worksheet.name$.top = $Worksheet.TopPosition$; /* Set default Vert position */
theWindowLocRec.Loc_$Worksheet.name$.right = theWindowLocRec.Loc_$Worksheet.name$.left;
theWindowLocRec.Loc_$Worksheet.name$.bottom = theWindowLocRec.Loc_$Worksheet.name$.top;
$$endif Worksheet.SavePosition
this->RecPtr = nil; /* No open windows yet */
this->ListRecPtr = nil;
}
/* ======================================================= */
/* Routine: Close */
/* Purpose: Close out the window */
void CmmW$Worksheet.name$::Close(WindowPtr whichWindow)
{
$Worksheet.name$PRec ckWS,theWS;
$$if Worksheet.SavePosition
Point theFinalPosition;
Rect temp2Rect;
$$endif Worksheet.SavePosition
if (whichWindow == (WindowPtr)-1)
whichWindow = FrontWindow();
this->LocateInstance(whichWindow);
/* See if we should close this window */
if (this->RecPtr != nil)
{
theWS = this->RecPtr;
this->CloseExtras((Ptr)theWS); /* HOOK for user */
$$Loop Control.type = EditText
if (theInput == theWS->TE_$Control.name$) /* See if this Text Edit field handle */
theInput = nil; /* Clear the handle used */
$$if Control.Global
Get_TE_String(theWS->TE_$Control.name$,(Str255 *)&theWS->TEStr_$Control.name$);
$$endif Control.Global
TEDispose(theWS->TE_$Control.name$); /* Dispose of a List, $Control.FullName$ */
$$EndLoop
$$Loop Control.type = List
LDispose(theWS->List_$Control.name$); /* Dispose of a List, $Control.FullName$ */
$$EndLoop
$$if Worksheet.SavePosition
SetPort(whichWindow); /* Select our window */
theFinalPosition.h = 0;
theFinalPosition.v = 0;
LocalToGlobal(&theFinalPosition); /* Get global location */
theWindowLocRec.Loc_$Worksheet.name$.left = theFinalPosition.h;
theWindowLocRec.Loc_$Worksheet.name$.top = theFinalPosition.v;
temp2Rect = theWS->theWindow->portRect; /* Get the window rectangle */
theWindowLocRec.Loc_$Worksheet.name$.right = theWindowLocRec.Loc_$Worksheet.name$.left
+ (temp2Rect.right - temp2Rect.left);
theWindowLocRec.Loc_$Worksheet.name$.bottom = theWindowLocRec.Loc_$Worksheet.name$.top
+ (temp2Rect.bottom - temp2Rect.top);
$$endif Worksheet.SavePosition
Mk_CloseLayeredWindow(whichWindow); /* Notify the layer code that we are closing */
DisposeWindow(whichWindow); /* Clear window and controls */
ckWS = this->ListRecPtr;
if (ckWS == theWS) /* See if first in the list */
{
this->ListRecPtr = theWS->Next; /* Use second one as new first */
DisposePtr((Ptr)theWS); /* Get rid of this one */
}
else
{
while (ckWS != nil) /* Loop thru them all */
{
if (ckWS->Next == theWS) /* See if the next one is a match */
{
ckWS->Next = theWS->Next; /* Get new next one */
DisposePtr((Ptr)theWS); /* Get rid of this one */
ckWS = nil; /* Get us out of the loop */
}
else
ckWS = ckWS->Next; /* Try the next one */
}
}
this->RecPtr = nil; /* No active one */
$$Link Worksheet.Close
}
}
/* ======================================================= */
/* Routine: Resized */
/* Purpose: We were resized or zoomed, update the scrolling scrollbars */
void CmmW$Worksheet.name$::Resized(Rect *OldRect,WindowPtr whichWindow)
{
WindowPtr SavePort; /* Place to save the last port */
Rect temp2Rect; /* temp rectangle */
short Index; /* temp integer */
ControlHandle ScrollHandle;
$Worksheet.name$PRec theWS;
LocateInstance(whichWindow);
if (this->RecPtr != nil) /* Only do if the window is us */
{
theWS = this->RecPtr;
GetPort(&SavePort); /* Save the current port */
SetPort(whichWindow); /* Set the port to my window */
$$if Worksheet.Document
temp2Rect = theWS->theWindow->portRect; /* Get the window rectangle */
EraseRect(&temp2Rect); /* Erase the new window area */
InvalRect(&temp2Rect); /* Set to update the new window area */
$$if Worksheet.ScrollHorz
if (theWS->ScrollHHandle != nil) /* Only do if the control is valid */
{
ScrollHandle = theWS->ScrollHHandle;
HLock((Handle)ScrollHandle); /* Lock the handle while we use it */
tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
tempRect.top = tempRect.top - 4; /* Widen the area to update */
tempRect.right = tempRect.right + 16; /* Widen the area to update */
InvalRect(&tempRect); /* Flag old position for update routine */
tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
temp2Rect = whichWindow->portRect; /* Get the window rectangle */
Index = temp2Rect.right - temp2Rect.left - 13;/* Get the scroll area width */
tempRect.left = theWS->ScrollHLeftOffset;
HideControl(ScrollHandle); /* Hide it during size and move */
SizeControl(ScrollHandle, Index,16); /* Make it 16 pixels high, std width */
MoveControl(ScrollHandle,tempRect.left,temp2Rect.bottom - temp2Rect.top-15);/* Size it correctly */
ShowControl(ScrollHandle); /* Safe to show it now */
HUnlock((Handle)ScrollHandle); /* Let it float again */
}
$$endif
$$if Worksheet.ScrollVert
if (theWS->ScrollVHandle != nil) /* Only do if the control is valid */
{
ScrollHandle = theWS->ScrollVHandle;
HLock((Handle)ScrollHandle); /* Lock the handle while we use it */
tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
tempRect.left = tempRect.left - 4; /* Widen the area to update */
tempRect.bottom = tempRect.bottom + 16; /* Widen the area to update */
InvalRect(&tempRect); /* Flag old position for update routine */
tempRect = (*ScrollHandle)->contrlRect; /* Get the last control position */
temp2Rect = whichWindow->portRect; /* Get the window rectangle */
Index = temp2Rect.bottom - temp2Rect.top - 13;/* Get the scroll area height */
tempRect.top = theWS->ScrollVTopOffset;
HideControl(ScrollHandle); /* Hide it during size and move */
SizeControl(ScrollHandle,16,Index); /* Make it 16 pixels high, std height */
MoveControl(ScrollHandle,temp2Rect.right - temp2Rect.left-15,tempRect.top);/* Size it correctly */
ShowControl(ScrollHandle); /* Safe to show it now */
HUnlock((Handle)ScrollHandle); /* Let it float again */
}
$$endif
$$endif Worksheet.Document
this->Moved(OldRect,whichWindow); /* The window was zoomed or resized */
SetPort(SavePort); /* Restore the old port */
}
}
/* ======================================================= */
/* Routine: Update */
/* Purpose: Update our window */
void CmmW$Worksheet.name$::Update(WindowPtr whichWindow)
{
WindowPtr SavePort; /* Place to save the last port */
$$if Worksheet.Icons
Handle Icon_Handle; /* Handle used in displaying icons */
$$endif Worksheet.Icons
$$if Worksheet.Pictures
PicHandle Pic_Handle; /* Handle used in displaying pictures */
$$endif Worksheet.Pictures
RGBColor Saved_ForeColor; /* Place to save colors */
RGBColor Saved_BackColor; /* Place to save colors */
RGBColor DrawingColor; /* Place to make colors */
$Worksheet.name$PRec theWS;
LocateInstance(whichWindow);
if (this->RecPtr != nil) /* Only do if the window is us */
{
theWS = this->RecPtr;
GetPort(&SavePort); /* Save the current port */
SetPort(whichWindow); /* Set the port to my window */
$$if Worksheet.HasControls
if (Has.ColorQD) /* See if color QuickDraw is around */
{
GetForeColor(&Saved_ForeColor); /* Save the fore color */
GetBackColor(&Saved_BackColor); /* Save the back color */
RGBForeColor(&Black_ForeColor); /* Set the fore color to Black */
RGBBackColor(&White_BackColor); /* Set the back color to White */
} /* End of IF */
$$Set TextSize = 12
$$Set TextFont = applFont
$$Set TextStyle = 0
$$Loop Control.type = StaticText
/* Draw static text, $Control.FullName$ */
$$if Control.TextColor ! Black
if (Has.ColorQD) /* See if color QuickDraw is around */
{
DrawingColor.red = 0x$Control.RedTextColor$;
DrawingColor.green = 0x$Control.GreenTextColor$;
DrawingColor.blue = 0x$Control.BlueTextColor$;
RGBForeColor(&DrawingColor); /* Set the fore color */
RGBBackColor(&Saved_BackColor); /* Set the back color */
}
$$endif Control.TextColor
$$if Control.MultipleLine
SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
DrawStaticTextBox(sResC_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
$$endif Control.MultipleLine
$$if Control.SingleLine
DrawStaticLine(sResC_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
$$endif Control.SingleLine
$$if Control.TextColor ! Black
if (Has.ColorQD) /* See if color QuickDraw is around */
{
RGBForeColor(&Black_ForeColor); /* Set the fore color */
RGBBackColor(&White_BackColor); /* Set the back color */
}
$$endif Control.TextColor
$$EndLoop
$$Loop Control.type = Icon
$$if Control.Graphic
/* Draw an Icon */
Icon_Handle = GetIcon(ResC_N_$Control.name$); /* Get Icon into memory */
SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
if (Icon_Handle != nil) /* Only use handle if it is valid */
PlotIcon(&tempRect,Icon_Handle); /* Draw the icon in the window */
$$endif Control.Graphic
$$EndLoop
$$Loop Control.type = Sicn
$$if Control.Graphic
/* Draw an sicn */
SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
Plot_Sicn(ResC_N_$Control.name$, &tempRect); /* Draw the sicn */
$$endif Control.Graphic
$$EndLoop
$$Loop Control.type = Picture
$$if Control.Graphic
/* Draw the Picture */
Pic_Handle = GetPicture(ResC_N_$Control.name$); /* Get Picture into memory */
SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
$$if Control.ClipPicture
if (Pic_Handle != nil) /* Only use handle if it is valid */
{
ClipRect(&tempRect); /* Clip picture to this rectangle */
HLock((Handle)Pic_Handle); /* Lock the handle before using it */
tempRect.right = tempRect.left + ((*Pic_Handle)->picFrame.right - (*Pic_Handle)->picFrame.left);
tempRect.bottom = tempRect.top + ((*Pic_Handle)->picFrame.bottom - (*Pic_Handle)->picFrame.top);
HUnlock((Handle)Pic_Handle); /* Unlock the picture again */
}
$$endif Control.ClipPicture
if (Pic_Handle != nil) /* Only use handle if it is valid */
DrawPicture(Pic_Handle, &tempRect); /* Draw this picture */
$$if Control.ClipPicture
SetRect(&tempRect, 0, 0, 32000, 32000); /* Widen the clip area again */
ClipRect(&tempRect); /* Set the clip area */
$$endif Control.ClipPicture
$$endif Control.Graphic
$$EndLoop
$$Loop Control.type = EditText
/* Draw Edit text */
$$if Control.TextColor ! Black
if (Has.ColorQD) /* See if color QuickDraw is around */
{
DrawingColor.red = 0x$Control.RedTextColor$;
DrawingColor.green = 0x$Control.GreenTextColor$;
DrawingColor.blue = 0x$Control.BlueTextColor$;
RGBForeColor(&DrawingColor); /* Set the fore color */
RGBBackColor(&Saved_BackColor); /* Set the back color */
}
$$endif Control.TextColor
DrawTheTEArea(&theWS->TERect_$Control.name$,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
$$if Control.TextColor ! Black
if (Has.ColorQD) /* See if color QuickDraw is around */
{
RGBForeColor(&Black_ForeColor); /* Set the fore color */
RGBBackColor(&White_BackColor); /* Set the back color */
}
$$endif Control.TextColor
$$EndLoop
$$Loop Control.type = Line
/* Draw a line, $Control.FullName$ */
$$if Control.GrayLine
PenPat(qd.gray); /* Set the gray pen pattern */
$$endif Control.GrayLine
$$if Control.LineWidth ! 1
PenSize($Control.LineWidth$,$Control.LineWidth$);
$$endif Control.LineWidth
MoveTo($Control.LeftPosition$,$Control.TopPosition$); /* Horz,vert, Move to starting position */
LineTo($Control.RightPosition$,$Control.BottomPosition$); /* Horz,vert, Draw to the ending position */
$$if Control.LineWidth ! 1
PenSize(1,1);
$$endif Control.LineWidth
$$if Control.GrayLine
PenPat(qd.black); /* Back to default pen pattern */
$$endif Control.GrayLine
$$EndLoop
$$Loop Control.type = List
/* Update a List */
UpdateTheList(theWS->theWindow->visRgn,theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
$$EndLoop
if (Has.ColorQD) /* See if color QuickDraw is around */
{
RGBForeColor(&Saved_ForeColor); /* Restore the fore color */
RGBBackColor(&Saved_BackColor); /* Restore the back color */
} /* End of IF */
$$endif Worksheet.HasControls
TextFont(applFont); /* Back to the application font */
TextSize(12); /* Back to the application size */
TextFace(0); /* Set text style */
this->UpdateExtras((Ptr)theWS); /* HOOK */
$$if Worksheet.Document
DrawGrowIcon(theWS->theWindow); /* Draw the Grow box */
$$endif Worksheet.Document
DrawControls(theWS->theWindow);
SetPort(SavePort); /* Restore the old port */
}
}
/* ======================================================= */
/* Routine: Open */
/* Purpose: Open our window */
void CmmW$Worksheet.name$::Open()
{
$$if Worksheet.Document
Rect temp2Rect; /* Used for scrollbar placement */
short ScrollAreaHeight; /* Used for scrollbar placement */
short ScrollAreaWidth; /* Used for scrollbar placement */
$$endif
WindowPtr BehindWindow; /* Used for window placement */
long theLong; /* Used for icons and hotspots definition */
$$if Worksheet.SavePosition
Point DefaultPosition; /* Used for window placement */
Point theWantedPosition;
$$endif
$Worksheet.name$PRec theWS;
if ((this->ListRecPtr == nil) || (this->MultipleInstances))
{
theWS = ($Worksheet.name$PRec)NewPtrClear(sizeof($Worksheet.name$Rec));
this->RecPtr = theWS;
theWS->Next = this->ListRecPtr;
this->ListRecPtr = theWS;
this->InitRecord(theWS);
BehindWindow = Mk_BehindWindow($Worksheet.Layer$); /* Get which window to place below */
if (Has.ColorQD) /* See if color QuickDraw is around */
theWS->theWindow = GetNewCWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the COLOR window from the resource file */
else
theWS->theWindow = GetNewWindow(ResW_$Worksheet.name$,nil,BehindWindow);/* Get the window from the resource file */
Mk_RegisterWindow(theWS->theWindow,$Worksheet.Layer$); /* Register the window with the layers */
SetPort(theWS->theWindow); /* Prepare to write into our window */
$$if Worksheet.Center
tempRect = theWS->theWindow->portRect; /* Get the windows position and size */
$$if Worksheet.CenterHorz
tempRect.left = ((screenRect.bounds.right -screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2; /* Center Horz */
$$endif Worksheet.CenterHorz
$$if Worksheet.CenterVert
tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3; /* 1/3 vert */
if (tempRect.top < 40) /* Keep below the menu bar */
tempRect.top = 40;
$$endif Worksheet.CenterVert
MoveWindow(theWS->theWindow,tempRect.left,tempRect.top,true);
$$endif
$$Loop Control.type = Button
/* Make a button */
theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,theWS->Enable_$Control.name$,0);
$$EndLoop Control.type = Button
$$Loop Control.type = Checkbox
/* Make a checkbox */
theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
$$EndLoop Control.type = Checkbox
$$Loop Control.type = Radio
/* Make a Radio */
theWS->Ctrl_$Control.name$ = MakeNormalControl(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,theWS->Value_$Control.name$);
$$EndLoop Control.type = Radio
$$Loop Control.type = HotRect
/* Make a HotSpot/rect */
theWS->Ctrl_$Control.name$ = MakeHotSpot(theWS->theWindow,ResC_$Control.name$,
$Control.MakeHotSpot$,$Control.LineWidth$,$Control.ShadowWidth$,sResC_$Control.name$,theWS->Enable_$Control.name$);
theWS->Rect_$Control.name$ = (*(theWS->Ctrl_$Control.name$))->contrlRect; /* Get the position */
$$EndLoop Control.type = HotRect
$$Loop Control.type = List
/* Make a List */
Make_A_List(&theWS->List_$Control.name$,&theWS->ListRect_$Control.name$,
theWS->theWindow,ResC_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
$$EndLoop Control.type = List
$$Loop Control.type = EditText
/* Open a TE box, $Control.FullName$ */
Make_TE_Area(&theWS->TE_$Control.name$,&theWS->TERect_$Control.name$,$Control.TextSize$,$Control.TextFont$,sResC_$Control.name$);/* Make the TE */
TESetText(&theWS->TEStr_$Control.name$[1],theWS->TEStr_$Control.name$[0],theWS->TE_$Control.name$);
$$EndLoop Control.type = EditText
$$Loop Control.type = Icon
$$if Control.NonGraphic
/* Make an icon button */
theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
$$endif Control.NonGraphic
$$EndLoop Control.type = Icon
$$Loop Control.type = Sicn
$$if Control.NonGraphic
/* Make an sicn button */
theWS->Ctrl_$Control.name$ = MakeIconSicn(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$);
$$endif Control.NonGraphic
$$EndLoop Control.type = Sicn
$$Loop Control.type = Picture
$$if Control.NonGraphic
/* Make an picture button */
theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
$$if Control.ClipPicture
theWS->Enable_$Control.name$,ResC_N_$Control.name$,1,0,0); /* Clipped */
$$endif Control.ClipPicture
$$if Control.ResizePicture
theWS->Enable_$Control.name$,ResC_N_$Control.name$,0,0,0); /* Resized */
$$endif Control.ResizePicture
$$endif Control.NonGraphic
$$EndLoop Control.type = Picture
$$Loop Control.type = ScrollBar
/* Make a scroll bar */
theWS->Ctrl_$Control.name$ = GetNewControl(ResC_$Control.name$,theWS->theWindow);/* Make a new scrollbar */
if (theWS->Enable_$Control.name$)
HiliteControl(theWS->Ctrl_$Control.name$,0); /* Enable the ScrollBar */
else
HiliteControl(theWS->Ctrl_$Control.name$,255); /* Disable the ScrollBar */
MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
$$EndLoop Control.type = ScrollBar
$$Loop Control.type = Popup
/* Make a Popup Menu */
theWS->Ctrl_$Control.name$ = MakePopupMenu(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,mResC_$Control.name$,theWS->Value_$Control.name$);
$$EndLoop Control.type = Popup
$$Loop Control.type = Palette
/* Make a Palette */
theWS->Ctrl_$Control.name$ = MakePalette(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,$Control.NumRows$,$Control.NumColumns$,ResC_N_$Control.name$,$Control.HMethod$);
$$EndLoop Control.type = Palette
$$Loop Control.type = UButton
/* Make a plugin button */
theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,0);
$$EndLoop Control.type = UButton
$$Loop Control.type = UToggle
/* Make a plugin toggle, $Control.FullName$ */
theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
$$EndLoop Control.type = UToggle
$$Loop Control.type = UGauge
/* Make a plugin gauge, $Control.FullName$ */
theWS->Ctrl_$Control.name$ = MakePlugin(theWS->theWindow,ResC_$Control.name$,
theWS->Enable_$Control.name$,ResC_N_$Control.name$,ResC_H_$Control.name$,0,theWS->Value_$Control.name$);
MakeMinMaxValue(theWS->Ctrl_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,theWS->Value_$Control.name$);
$$EndLoop Control.type = UGauge
$$if Worksheet.Document
$$if Worksheet.ScrollHorz
SetRect(&tempRect,1,1,1,1);
theWS->ScrollHHandle = NewControl(theWS->theWindow,&tempRect,"\pHorz Scroll",true,1,1,100,scrollBarProc,12345L);
this->Resized(&tempRect,theWS->theWindow);
HiliteControl(theWS->ScrollHHandle,255);
$$endif
$$if Worksheet.ScrollVert
SetRect(&tempRect,1,1,1,1);
theWS->ScrollVHandle = NewControl(theWS->theWindow,&tempRect,"\pVert Scroll",true,1,1,100,scrollBarProc,12346L);
this->Resized(&tempRect,theWS->theWindow);
HiliteControl(theWS->ScrollVHandle,255);
$$endif
$$endif Worksheet.Document
$$if Worksheet.SavePosition
SetPort(theWS->theWindow); /* Select our window */
DefaultPosition.h = 0; /* Reset Horz position */
DefaultPosition.v = 0; /* Reset Vert position */
LocalToGlobal(&DefaultPosition); /* Get global location */
theWantedPosition.h = theWindowLocRec.Loc_$Worksheet.name$.left;
theWantedPosition.v = theWindowLocRec.Loc_$Worksheet.name$.top;
PositionWindow(theWS->theWindow,theWantedPosition,DefaultPosition);
if (theWindowLocRec.Loc_$Worksheet.name$.left != theWindowLocRec.Loc_$Worksheet.name$.right)
{
SizeWindow(theWS->theWindow,theWindowLocRec.Loc_$Worksheet.name$.right - theWindowLocRec.Loc_$Worksheet.name$.left,
theWindowLocRec.Loc_$Worksheet.name$.bottom - theWindowLocRec.Loc_$Worksheet.name$.top,true);
SetRect(&tempRect,1,1,1,1);
this->Resized(&tempRect,theWS->theWindow);
}
$$endif Worksheet.SavePosition
this->OpenExtras((Ptr)theWS); /* HOOK */
ShowWindow(theWS->theWindow); /* Show the window now */
$$Link Worksheet.Open
}
else
theWS = this->ListRecPtr;
Mk_HiliteWindow(theWS->theWindow); /* Already open, so show it */
}
/* ======================================================= */
/* Routine: Activate */
/* Purpose: We activated or deactivated */
void CmmW$Worksheet.name$::Activate(WindowPtr whichWindow,Boolean Do_An_Activate)
{
WindowPtr SavePort; /* Place to save the last port */
$Worksheet.name$PRec theWS;
LocateInstance(whichWindow);
if (this->RecPtr != nil) /* Only do if the window is us */
{
theWS = this->RecPtr;
GetPort(&SavePort); /* Save the current port */
SetPort(whichWindow); /* Set the port to my window */
$$if Worksheet.Document
DrawGrowIcon(whichWindow); /* Draw the Grow box */
$$endif Worksheet.Document
if (!Do_An_Activate) /* Handle the deactivate */
{
if (theInput != nil) /* See if there is already a TE area */
TEDeactivate(theInput); /* Yes, so turn it off */
theInput = nil; /* Deactivate the TE area */
$$if Worksheet.Document
$$if Worksheet.ScrollHorz
HiliteControl(theWS->ScrollHHandle,255);
$$endif
$$if Worksheet.ScrollVert
HiliteControl(theWS->ScrollVHandle,255);
$$endif
$$endif Worksheet.Document
$$Link Worksheet.Deactivate
}
else
{
$$if Worksheet.Document
$$if Worksheet.ScrollHorz
HiliteControl(theWS->ScrollHHandle,0);
$$endif
$$if Worksheet.ScrollVert
HiliteControl(theWS->ScrollVHandle,0);
$$endif
$$endif Worksheet.Document
$$Link Worksheet.Activate
}
this->ActivateExtras(Do_An_Activate,(Ptr)theWS); /* HOOK */
SetPort(SavePort); /* Restore the old port */
}
}
/* ======================================================= */
/* Routine: Do_A_Button */
/* Purpose: Handle a button pressed */
void CmmW$Worksheet.name$::HandleButton(WindowPtr whichWindow,ControlHandle theControl) /* Handle a button being pressed */
{
long RefCon; /* RefCon for controls */
short UnHiliteValue; /* For unhilite */
short theSelection; /* For palettes and popups */
$Worksheet.name$PRec theWS;
LocateInstance(whichWindow);
if (this->RecPtr != nil) /* Only do if the window is us */
{
theWS = this->RecPtr;
HiliteControl(theControl,10); /* Darken the button */
UnHiliteValue = 0; /* To lighten the button */
RefCon = GetCRefCon(theControl); /* get control refcon */
switch (RefCon) /* Select correct button */
{
$$Loop Control.type = Button
$$if Control.HasLinks
case ResC_$Control.name$: /* Button, $Control.FullName$ */
$$Link Control.Select
break;
$$endif
$$EndLoop Control.type = Button
$$Loop Control.type = HotRect
$$if Control.HasLinks
$$if Control.HotSpot
case ResC_$Control.name$: /* HotSpot, $Control.FullName$ */
$$Link Control.Select
break;
$$endif Control.HotSpot
$$endif
$$EndLoop Control.type = HotRect
$$Loop Control.type = Icon
$$if Control.HasLinks
$$if Control.NonGraphic
case ResC_$Control.name$: /* Icon, $Control.FullName$ */
$$Link Control.Select
break;
$$endif Control.NonGraphic
$$endif
$$EndLoop Control.type = Icon
$$Loop Control.type = Sicn
$$if Control.HasLinks
$$if Control.NonGraphic
case ResC_$Control.name$: /* Sicn, $Control.FullName$ */
$$Link Control.Select
break;
$$endif Control.NonGraphic
$$endif
$$EndLoop Control.type = Sicn
$$Loop Control.type = Picture
$$if Control.HasLinks
$$if Control.NonGraphic
case ResC_$Control.name$: /* Picture, $Control.FullName$ */
$$Link Control.Select
break;
$$endif Control.NonGraphic
$$endif
$$EndLoop Control.type = Picture
$$Loop Control.type = UButton
$$if Control.HasLinks
case ResC_$Control.name$: /* Plugin Button, $Control.FullName$ */
$$Link Control.Select
break;
$$endif
$$EndLoop Control.type = UButton
$$Loop Control.type = Popup
case ResC_$Control.name$: /* PopUp, $Control.FullName$ */
theSelection = GetCtlValue(theWS->Ctrl_$Control.name$); /* Get the Popup selection value */
switch (theSelection) /* Select correct item */
{
$$Loop PopupItems
case $Control.PopupID$: /* $Control.PopupID$, for $Control.PopupName$ */
break;
$$EndLoop PopupItems
default: /* allow other buttons, trap for debug */
break; /* end of otherwise */
} /* end of switch */
break;
$$EndLoop Control.type = Popup
$$Loop Control.type = Palette
case ResC_$Control.name$: /* Tool palette, $Control.FullName$ */
theWS->Value_$Control.name$ = GetCtlValue(theWS->Ctrl_$Control.name$);/* Get the palette value, 0xrrcc, rr is row, cc is column */
break;
$$EndLoop Control.type = Palette
default: /* allow other buttons, trap for debug */
break; /* end of otherwise */
} /* end of switch */
this->HandleExtraButtons((Ptr)theWS,theControl,&UnHiliteValue);
HiliteControl(theControl,UnHiliteValue); /* Lighten the button */
}
} /* End of Handle a button being pressed */
$$if Worksheet.CheckboxesOrRadios
/* ======================================================= */
void CmmW$Worksheet.name$::HandleCheckbox(WindowPtr whichWindow,ControlHandle theControl)/* Handle a checkbox being pressed */
{
long RefCon; /* RefCon for controls */
short theValue; /* Current value of a control */
$Worksheet.name$PRec theWS;
LocateInstance(whichWindow);
if (this->RecPtr != nil) /* Only do if the window is us */
{
theWS = this->RecPtr;
RefCon = GetCRefCon(theControl); /* get control refcon */
theValue = GetCtlValue(theControl); /* Get current value */
theValue = (theValue + 1) & 1; /* Change value from 1 to 0 or from 0 to 1 */
switch (RefCon) /* Select correct control */
{
$$Loop Control.type = Checkbox
case ResC_$Control.name$: /* Checkbox, $Control.FullName$ */
SetCtlValue(theControl, theValue); /* Set checkbox to new value */
theWS->Value_$Control.name$ = theValue;
$$if Control.HasLinks
if (theValue == 0)
{
$$Link Control.Deselect
}
else
{
$$Link Control.Select
}
$$endif
break;
$$EndLoop Control.type = Checkbox
$$Loop Control.type = UToggle
case ResC_$Control.name$: /* Plugin Toggle, $Control.FullName$ */
SetCtlValue(theControl, theValue); /* Set checkbox to new value */
theWS->Value_$Control.name$ = theValue;
$$if Control.HasLinks
if (theValue == 0)
{
$$Link Control.Deselect
}
else
{
$$Link Control.Select
}
$$endif
break;
$$EndLoop Control.type = UToggle
$$Loop Control.type = Radio
case ResC_$Control.name$: /* Radio, $Control.FullName$ */
theWS->Value_$Control.name$ = 1; /* Set the Radio value */
SetCtlValue(theControl,1); /* Select this Radio */
/* Clear other Radio values in this group */
$$Loop RadioGroup
SetCtlValue(theWS->Ctrl_$Control.name$,0);
theWS->Value_$Control.name$ = 0; /* Clear other radio */
$$EndLoop RadioGroup
$$Link Control.Select
break;
$$EndLoop Control.type = Radio
default: /* allow other checkboxes and radios, trap for debug */
break; /* end of otherwise */
} /* end of case */
this->HandleExtraCheckboxes((Ptr)theWS,theControl);
}
}
$$endif
/* ======================================================= */
/* Routine: HandleEvent */
/* Purpose: Handle action to our window, like controls */
void CmmW$Worksheet.name$::HandleEvent(EventRecord *myEvent)
{
short code; /* Location of event in window or controls */
WindowPtr whichWindow; /* Window pointer where event happened */
Point myPt; /* Point where event happened */
ControlHandle theControl; /* Handle for a control */
$Worksheet.name$PRec theWS;
code = FindWindow(myEvent->where,&whichWindow); /* Get where in window and which window */
LocateInstance(whichWindow);
if (this->RecPtr != nil) /* Only do if the window is us */
{
theWS = this->RecPtr;
$$if HasEditLists
if (myEvent->what == mouseDown)
{
myPt = myEvent->where; /* Get mouse position */
GlobalToLocal(&myPt); /* Make it relative */
$$Loop Control.type = EditText
if (PtInRect(myPt,&theWS->TERect_$Control.name$)) /* Check for pressed in the TE Edit Text */
{
Activate_TE_Area(false,myPt,theWS->TE_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
whichWindow = NIL; /* Do not let anyone else handle it */
}
$$EndLoop Control.type = EditText
$$Loop Control.type = List
if (PtInRect(myPt,&theWS->ListRect_$Control.name$))
{
ClickInTheList(myPt,myEvent->modifiers,theWS->List_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,false);
whichWindow = NIL; /* Do not let anyone else handle it */
}
$$EndLoop Control.type = List
}
$$endif HasEditLists
if ((theWS->theWindow == whichWindow) && (code == inContent)) /* for our window */
{
myPt = myEvent->where; /* Get mouse position */
GlobalToLocal(&myPt); /* Make it relative */
code = FindControl(myPt,whichWindow,&theControl); /* Get type of control */
$$if Worksheet.Scrollbars
if ((code == inUpButton) || (code == inDownButton) || (code == inThumb) || (code == inPageDown) || (code == inPageUp))
this->HandleScrollBar(code,theControl,myPt); /* Do scrollbars */
else
$$endif
if (code != 0) /* Check type of control */
code = TrackControl(theControl,myPt,(ControlActionUPP)-1);/* Track the control */
if (code == inButton)
this->HandleButton(whichWindow,theControl); /* Do buttons */
$$if Worksheet.CheckboxesOrRadios
else if (code == inCheckBox)
this->HandleCheckbox(whichWindow,theControl); /* Do checkboxes and radios */
$$endif
}
}
}
/* ======================================================= */
/* ======================================================= */
$$CloseFile
$$EndLoop